package com.uwlaser.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.service.ProductModelLienService;
import com.uwlaser.service.dto.ProductModelLienDto;
import com.uwlaser.service.dto.ProductModelLienQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
* @author zk-Qin
* @date 2022-05-31
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "产品产线关联管理")
@RequestMapping("/api/productModelLien")
public class ProductModelLienController {

    private final ProductModelLienService productModelLienService;

    @GetMapping
    @Log("查询产品产线关联")
    @ApiOperation("查询产品产线关联")
    @PreAuthorize("@el.check('productModelLien:list')")
    public ResponseEntity query(ProductModelLienQueryParam query, Pageable pageable){
        return new ResponseEntity<>(productModelLienService.queryAll(query,pageable),HttpStatus.OK);
    }

    @GetMapping("/list")
    @Log("查询产品产线关联")
    @ApiOperation("查询产品产线关联")
    @PreAuthorize("@el.check('productModelLien:list')")
    public ResponseEntity list(ProductModelLienQueryParam query){
        return new ResponseEntity<>(productModelLienService.queryAll(query),HttpStatus.OK);
    }

    @GetMapping("/getProductByLine")
    @Log("根据产线查询产品")
    @ApiOperation("根据产线查询产品")
    @PreAuthorize("@el.check('productModelLien:list')")
    public ResponseEntity getProductByLine(ProductModelLienQueryParam query){
        return new ResponseEntity<>(productModelLienService.getProductByLine(query),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增产品产线关联")
    @ApiOperation("新增产品产线关联")
    @PreAuthorize("@el.check('productModelLien:add')")
    public ResponseEntity create(@Validated @RequestBody ProductModelLienDto resources){
        return new ResponseEntity<>(productModelLienService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改产品产线关联")
    @ApiOperation("修改产品产线关联")
    @PreAuthorize("@el.check('productModelLien:edit')")
    public ResponseEntity update(@Validated @RequestBody ProductModelLienDto resources){
        productModelLienService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除产品产线关联")
    @ApiOperation("删除产品产线关联")
    @PreAuthorize("@el.check('productModelLien:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        productModelLienService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出产品产线关联")
    @ApiOperation("导出产品产线关联")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('productModelLien:list')")
    public void download(HttpServletResponse response, ProductModelLienQueryParam query) throws IOException {
        productModelLienService.download(productModelLienService.queryAll(query), response);
    }*/

}
